package com.cx.utils;

import java.util.ArrayList;
import java.util.List;

public class Pages {
    private Integer currentPage;
    private Integer pageSize;
    private Integer totalCount;

    private Integer totalPage;
    private Integer prePage;
    private Integer nextPage;
    private List<Integer> pageList;

//    计算页面
    public List<Integer> getPageList(){
        pageList = new ArrayList<>();
        for (int i = 1; i <=getTotalPage(); i++) {
            pageList.add(i);
        }
        return pageList;
    }


    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getTotalPage() {
        if (getTotalCount()%getPageSize()==0){
            totalPage = getTotalCount() / getPageSize();
        }else {
            totalPage = getTotalCount() / getPageSize() + 1;
        }
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getPrePage() {
        if (getCurrentPage()<=1){
            prePage = 1;
        }else {
            prePage = getCurrentPage() - 1;
        }
        return prePage;
    }

    public void setPrePage(Integer prePage) {
        this.prePage = prePage;
    }

    public Integer getNextPage() {
        if (getCurrentPage()>=getTotalPage()){
            nextPage = getCurrentPage();
        }else {
            nextPage = getCurrentPage() + 1;
        }
        return nextPage;
    }

    public void setNextPage(Integer nextPage) {
        this.nextPage = nextPage;
    }

    @Override
    public String toString() {
        return "Pages{" +
                "currentPage=" + currentPage +
                ", pageSize=" + pageSize +
                ", totalCount=" + totalCount +
                ", totalPage=" + totalPage +
                ", prePage=" + prePage +
                ", nextPage=" + nextPage +
                ", pageList=" + pageList +
                '}';
    }
}
